<!-- 装修名片组件 -->
<template>
  <div id="U_businessCard">
    <div class="header_box" :style="bacImage" v-if="cardMessage.uid">
        <div class="header" @click.stop="gotoBusiness">
          <div class="img">
            <img :src="cardMessage.avatar" />
          </div>
          <div class="collect" @click.stop="changeLike">
            <i v-if="cardMessage.card_status && cardMessage.card_status.collected" class="iconfont icon-bc_like"></i>
            <i v-else class="iconfont icon-bc_like_normal"></i>
            <span class="people">{{ cardMessage.collection }}人收藏</span>
          </div>
        </div>
        <ul class="per_info">
          <li style="display: flex; flex-direction: column; margin-bottom: 1rem;">
            <p class="card-name">{{ cardMessage.nickname }}</p>
            <div v-if="cardMessage.role_name">
              <span class="role-name">{{ cardMessage.role_name.role_name }}</span>
              <span class="level-name">{{ cardMessage.role_name.level_name }}</span>
            </div>
            <div class="flex-a-c" v-if="cardMessage.is_auth_open">
              <div class="flex-a-c certification-box certification-box-bg-fff">
                <i class="iconfont icon-baoming"></i>
                <div class="text">{{cardMessage.person.status?'会员已认证':'会员未认证'}}</div>
              </div>
              <div class="flex-a-c certification-box" >
                <i class="iconfont icon-icon_company"></i>
                <div class="text">{{cardMessage.company.length > 0?'企业已认证':'企业未认证'}}</div>
              </div>
            </div>
          </li>
          <li v-if="cardMessage.card_mobile" class="items-center">
            <i class="iconfont icon-zx_map_tel"></i>
            <a :href="`tel:${cardMessage.card_mobile}`" class="fz-24">{{ cardMessage.card_mobile }}</a>
          </li>
          <li v-if="cardMessage.card_wechat" class="items-center">
            <i class="iconfont icon-card_weixin"></i>
            <span class="fz-24">{{ cardMessage.card_wechat }}</span>
          </li>
          <li v-if="cardMessage.is_auth_open && cardMessage.company && cardMessage.company[0]" class="items-center">
            <i class="iconfont icon-gongsi"></i>
            <span class="fz-24">
              <em v-for="(company,cindex) in cardMessage.company" :key="cindex">{{company.name}}<br></em>
            </span>
          </li>
          <li v-else-if="!cardMessage.is_auth_open && cardMessage.company_name" class="items-center">
            <i class="iconfont icon-gongsi"></i>
            <span class="fz-24">{{cardMessage.company_name}}</span>
          </li>
          <li class="position items-center" v-if="cardMessage.areas && cardMessage.areas[0]">
            <i class="iconfont icon-zx_map_locate1"></i>
            <span class="fz-24" style="-webkit-box-orient: vertical;">{{ area_name }}</span>
          </li>
        </ul>
      </div>
  </div>
</template>

<script>
export default {
  props: ['id', 'datas',"page_id"],
  data () {
    return {
      cardMessage: {},
      area_name: '',
      bacImage: ''
    };
  },

  activated() {},

  components: {},

  computed: {},

  created() {
    const needLocation = ["4"];//需要请求定位的规则
    const isNeedLocation = this.datas.user.some(item => needLocation.includes(item.type));
    if(isNeedLocation) {
      this.fun
        .getLocation()
        .then(res => {
          this.point = res.point;
          let p = this.fun.bd_encrypt(this.point.lng, this.point.lat);
          this.getBusinessUser({lng: p.lng,lat: p.lat});
        })
        .catch(err => {
          console.log(err);
        });
    } else {
      this.getBusinessUser();
    }
  },

  methods: {
    gotoBusiness() {
      this.$router.push(this.fun.getUrl("BusinessCard", {}, { mark_id: this.cardMessage.card_id, mark: "card" }));
    },
    async getBusinessUser(extinfo={}){
      let shrID = sessionStorage.getItem("shrID");//分享者id
      if(this.fun.getKey('shrID')) {
        shrID = this.fun.getKey('shrID');
      }
      let json = { component_id: this.id,decorate_id: this.page_id, ...extinfo };
      if(shrID) json.shrID = shrID;
      let { msg, result, data } = await $http.get('plugin.business-card.frontend.controllers.card.card.getDecorate', json, ".");
      this.cardMessage = data||null;
      if(this.cardMessage.areas) this.area_name = this.cardMessage.areas.join("") + this.cardMessage.address;
      if (this.cardMessage.thumb) {
        this.bacImage = { backgroundImage: "url(" + this.cardMessage.thumb + ")" };
      }
    },
    changeLike(type) {
      $http
        .get("plugin.business-card.frontend.controllers.action.card-action.index", { card_id: this.cardMessage.card_id, card_type: 1 }, " ")
        .then(
          response => {
            if (response.result === 1) {
              this.cardMessage.card_status.collected = response.data;
              if(response.data){
                this.cardMessage.collection++;
              }else{
                if( this.cardMessage.collection <= 0){
                  this.cardMessage.collection = 0;
                }else{
                  this.cardMessage.collection--;
                }
              }
            } else {
              this.$toast("本人名片不能进行该操作");
            }
          },
          function(response) {
            console.log(response);
          }
        )
        .catch(error => {
          console.log(error);
        });
    },
  }
}

</script>
<style lang='scss' rel='stylesheet/scss' scoped>
.header_box {
      display: flex;
      flex-direction: row-reverse;
      justify-content: space-between;
      background-image: url("https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/business_card/business_card_bg.png");
      background-repeat: no-repeat;
      background-size: 100% 100%;
      padding: 1.25rem 1rem 1.8438rem 0.9375rem;
      border-radius: 0.625rem;
      overflow: hidden;
      margin:0 0.75rem;

      .header {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;

        .iconfont {
          font-size: 1.5rem
        }

        .img {
          width: 3.75rem;
          height: 3.75rem;
          border-radius: 1.875rem;
          overflow: hidden;
          background: #f2f2f2;
          margin-bottom: 0.75rem;
          align-self: end;
          border: 2px solid #fff;

          img {
            width: 100%;
            height: 100%;
          }
        }

      }

      .per_info {
        text-align: left;
        .certification-box {
          margin: 0.5rem 0.625rem 0 0;
          height: 1rem;
          background: linear-gradient(318deg, rgba(255,211,154,0.85) 0%, rgba(255,229,97,0.13) 100%);
          border-radius: 6px;
          opacity: 1;
          .text{
            font-size: 0.5625rem;
            margin-right: 6px;
            color: #fff;
          }
        }
        .certification-box-bg-fff{
          background: linear-gradient(318deg, rgba(216,216,216,0.48) 0%, rgba(255,255,255,0.13) 100%);
        }

        .card-name {
          font-weight: bold;
          color: #FAFAFA;
          font-size: 1.3125rem;
        }

        .role-name {
          margin-right: 0.4375rem;
        }

        .role-name,
        .level-name {
          font-size: 0.75rem;
          color: #fff;
          font-weight: 500;
        }

        .items-center {
          align-items: center;
        }

        .fz-24 {
          font-size: 0.75rem !important;
        }

        li {
          // line-height: 1.5rem;
          margin-bottom: 0.5rem;
          display: flex;

          .icon-card_weixin {
            font-size: .6rem;
          }

          .icon-gongsi,
          .icon-zx_map_locate1 {
            font-size: .5rem;
            flex-shrink: 0;
          }

          .icon-zx_map_tel {
            font-size: .4rem;
            flex-shrink: 0;
          }


          i {
            position: relative;
            width: 1rem;
            height: 1rem;
            line-height: 1rem;
            background: url("https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/business_card/business_card_icon_bg.png");
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            text-align: center;
            color: #fff;
            margin-right: 0.3125rem;
            font-size: 0.5625rem;
            opacity: .8;
          }

          span {
            font-size: 14px;
            color: #fff;
          }

          a {
            font-size: 14px;
            color: #fff;
          }
        }

        .position {
          align-items: flex-start;
          span {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
        }
      }
    }

    .collect {
      position: relative;
      border-radius: 0.9375rem;
      min-width: 3.375rem;
      height: 3.375rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      color: #fff;
    }

    .people {
      font-size: 0.625rem;
      font-weight: 400;
    }

    .collect::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      background: #FFFFFF;
      border-radius: 0.9375rem;
      bottom: 0;
      opacity: 0.2;
    }
</style>